//
//  BaseModel.m
//  MountEverestFM
//
//  Created by ChenNing on 15/10/28.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

// 通过一个字典创建一个model对象
+ (instancetype)modelWithDic:(NSDictionary *)dic
{
    // 1, self:(类调用+号方法,谁调用它,self就是谁,所以self是调用它的那个类)
    // 2, (多态的概念)父类的指针可以指向子类的对象,所以,等号右面是子类,等号左面是父类,父类指向了子类的对象
    BaseModel *base = [[self alloc] init];
    [base setValuesForKeysWithDictionary:dic];
    return base;
}

// 通过一个装满字典的数组,封装一个装满model的数组
+ (NSArray *)modelWithArr:(NSArray *)dicArr
{
    NSMutableArray *sourceArr = [[NSMutableArray alloc] init];
    for (NSDictionary *dic in dicArr) {
        BaseModel *base = [self modelWithDic:dic];
        [sourceArr addObject:base];
    }
    return sourceArr;
}

// 1,KVC 纠错方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    NSLog(@"%@__%@",value,key);
    if ([key isEqualToString:@"playPath64"]) {
        [self setValue:value forKey:@"playUrl64"];
    }
}
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}
@end
